package edu.hubu.talentmanagementsystem.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import edu.hubu.talentmanagementsystem.model.ext.Company;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Mapper
public interface CompanyMapper extends BaseMapper<Company> {
    int insert(Company entity);

    int deleteById(Serializable id);

    int deleteByMap(@Param("cm") Map<String, Object> columnMap);

    int delete(@Param("ew") Wrapper<Company> queryWrapper);

    int deleteBatchIds(@Param("coll") Collection<? extends Serializable> idList);

    int updateById(@Param("et") Company entity);

    int update(@Param("et") Company entity, @Param("ew") Wrapper<Company> updateWrapper);

    Company selectById(Serializable id);

    List<Company> selectBatchIds(@Param("coll") Collection<? extends Serializable> idList);

    List<Company> selectByMap(@Param("cm") Map<String, Object> columnMap);

    Company selectOne(@Param("ew") Wrapper<Company> queryWrapper);

    Integer selectCount(@Param("ew") Wrapper<Company> queryWrapper);

    List<Company> selectList(@Param("ew") Wrapper<Company> queryWrapper);

    List<Map<String, Object>> selectMaps(@Param("ew") Wrapper<Company> queryWrapper);

    List<Object> selectObjs(@Param("ew") Wrapper<Company> queryWrapper);

    <E extends IPage<Company>> E selectPage(E page, @Param("ew") Wrapper<Company> queryWrapper);

    <E extends IPage<Map<String, Object>>> E selectMapsPage(E page, @Param("ew") Wrapper<Company> queryWrapper);

    @Select("select * from company where company_num=#{num}")
    Company selectByNum(@Param("num") String num);

    @Select("select company_id,company_name,company_logo_id,company_phone_number,company_big_tag from company where company_id in" +
            "(select company_star_company_id from company_star where company_star_staff_id = #{staffId}) ")
    @Results({
            @Result(column = "company_big_tag", property = "positionBigTag",
                    one = @One(select = "edu.hubu.talentmanagementsystem.mapper.PositionBigTagMapper.selectByBigTagId")),
            @Result(column = "company_logo_id", property = "resource",
                    one = @One(select = "edu.hubu.talentmanagementsystem.mapper.ResourceMapper.selectByResourceId"))
    })
    List<Company> selectStaffFollowCompanies(Integer staffId);

    @Select("select company_name from company where company_id = #{company_name}")
    Company selectNameById(Integer companyId);
}